package com.nunbey.lingxi.module.list;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.nunbey.lingxi.R;
import com.nunbey.lingxi.module.mode.doctors.DoctorInfo;

import java.util.ArrayList;

/**
 * 首页医生列表
 */
public class DoctorRecycleView {

    private static class DoctorHolder extends RecyclerView.ViewHolder{
        private final ImageView head;
        private final TextView name;
        private final TextView affiliation;
        private final TextView skill;
        public DoctorHolder(@NonNull View itemView) {
            super(itemView);
            this.head = itemView.findViewById(R.id.list_doctor_image);
            this.name = itemView.findViewById(R.id.list_doctor_name);
            this.affiliation = itemView.findViewById(R.id.list_doctor_affiliation);
            this.skill = itemView.findViewById(R.id.list_doctor_skill);
        }
    }

    public static class DoctorRecycleViewAdapter extends RecyclerView.Adapter{

        ArrayList<DoctorInfo> doctorInfos;

        Context context;



        public  DoctorRecycleViewAdapter(ArrayList<DoctorInfo> doctorInfos, Context context){
            this.doctorInfos=doctorInfos;
            this.context=context;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_doctor,parent,false);
            DoctorRecycleView.DoctorHolder doctorHolder = new DoctorRecycleView.DoctorHolder(view);

            return doctorHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            DoctorInfo doctorInfo = doctorInfos.get(position);
            DoctorRecycleView.DoctorHolder doctorHolder = (DoctorRecycleView.DoctorHolder) holder;
            Glide.with(context).load(doctorInfo.getHeadPicUrl()).into(doctorHolder.head);
            doctorHolder.name.setText(doctorInfo.getName());
            doctorHolder.affiliation.setText(doctorInfo.getAffiliation());
            doctorHolder.skill.setText(doctorInfo.getSkill());
        }

        @Override
        public int getItemCount() {
            return doctorInfos.size();
        }
    }
}
